import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { prismjsPlugin } from 'vite-plugin-prismjs'
import vue from '@vitejs/plugin-vue'

export default defineConfig((command, mode) => {
  const publicDir = resolve('resources')
  const envDir = resolve('build')
  return {
    main: {
      resolve: {
        alias: {
          '@': resolve('src/main'),
          '@build': resolve('build'),
          '@resources': resolve('resources')
        }
      },
      plugins: [externalizeDepsPlugin()]
    },
    preload: {
      plugins: [externalizeDepsPlugin()]
    },
    renderer: {
      publicDir,
      envDir,
      envPrefix: 'RENDERER_',
      resolve: {
        extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
        alias: {
          '@module': resolve('node_modules'),
          '@renderer': resolve('src/renderer/src'),
        }
      },
      server: {
        proxy: {
          "/api": {
            target: "http://192.168.1.2:9999",
            changeOrigin: true,
            rewrite: path => path.replace(/^\/api/, "")
          }
        },
        host: true
      },
      plugins: [
        vue(),
        prismjsPlugin({
          languages: 'all',
          // 配置行号插件
          plugins: ['line-numbers', 'show-language', 'copy-to-clipboard'],
          css: true
        })
      ]
    }
  }
})
